package org.zoomdev.zoom.asm;

import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

public class FieldBuilder {
    private final String name;
    private Type type;
    private int access = Opcodes.ACC_PRIVATE;
    private Object value;

    public FieldBuilder(String name) {
        this.name = name;
    }

    public FieldBuilder withAccess(int access) {
        this.access = access;
        return this;
    }

    public FieldBuilder withType(Class<?> type) {
        this.type = Type.getType(type);
        return this;
    }

    public FieldBuilder withValue(Object value) {
        this.value = value;
        return this;
    }

    public void build(ClassWriter cw) {
        FieldVisitor fv = cw.visitField(access, name, type.getDescriptor(), null, value);
        fv.visitEnd();
    }
}
